package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.PageEntity;
import com.smz.entity.TEnterprise;
import com.smz.service.TEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api
@RestController
public class TEnterpriseController {

    @Autowired
    private TEnterpriseService tEnterpriseService;

    @ApiOperation("分页查询")
    @GetMapping("/tEnterprises/page")
    public ResponseEntity<PageEntity<TEnterprise>> findTEnterprisesPage(@RequestParam(value = "current",required = false,defaultValue = "1")
                                                                      Integer current){
        PageEntity<TEnterprise> tEnterprisesPage = tEnterpriseService.findTEnterprisesPage(current);
        System.out.println(tEnterprisesPage);
        return ResponseEntity.ok(tEnterprisesPage);
    }

    @ApiOperation("查询所有")
    @GetMapping("/tEnterprises")
    public ResponseEntity<List<TEnterprise>> findAllTEnterprises(){
        List<TEnterprise> all =tEnterpriseService.findAllTEnterprises() ;
        return ResponseEntity.ok(all);
    }

    @ApiOperation("通过id查")
    @GetMapping("/tEnterprises/{id}")
    public ResponseEntity<TEnterprise> findTEnterpriseById(@PathVariable("id")Integer id){
        TEnterprise tEnterprise = tEnterpriseService.findTEnterpriseById(id);
        return ResponseEntity.ok(tEnterprise);
    }

    @ApiOperation("模糊查询")
    @GetMapping("/tEnterpriseLike/like/{start}/{length}/{contacts}/{enterpriseName}")
    public ResponseEntity<IPage<TEnterprise>> findTEnterpriseByContactsEnterpriseName(@PathVariable("start") Integer start,
                                                                                      @PathVariable("length") Integer length,
                                                                                      @PathVariable("contacts") String contacts,
                                                                                      @PathVariable("enterpriseName") String enterpriseName)  {
        IPage<TEnterprise> tEnterpriseByContactsEnterpriseName = tEnterpriseService.findTEnterpriseByContactsEnterpriseName(start, length, contacts, enterpriseName);

        return ResponseEntity.ok(tEnterpriseByContactsEnterpriseName);
    }

    @ApiOperation("通过id查")
    @GetMapping("/tEnterprises/{id}/{accountStatus}")
    public ResponseEntity<String> findTEnterpriseById(@PathVariable("id")Integer id , @PathVariable("accountStatus") String accountStatus ){
         tEnterpriseService.modifyTEnterpriseById(id,accountStatus);
        return ResponseEntity.ok("ok");
    }
}
